(async () => {
    //分类列表
    // 获取数据
    let shopps = await fetch('http://localhost:3001/categorys');
    let shop_data = await shopps.json();

    // 获取元素
    // let imagesDiv = document.querySelector('.img');
    let titlesText = document.querySelector('.all');


    // 遍历数据，创建元素并添加到页面
    for (let i = 0; i < shop_data.length; i++) {
        if (shop_data[i]._id == 13 || shop_data[i]._id == 3 || shop_data[i]._id == 4 || shop_data[i]._id == 14 || shop_data[i]._id == 15) {
            let title = document.createElement('div');
            let titleData = shop_data[i];
            let img = document.createElement('img');
            img.src = 'http://localhost:3001' + shop_data[i].img;

            // 已获取数据加入缓存
            let titleDatas = [];
            titleDatas.push(titleData);

            // 构建内容
            title.className = 'new';
            title.innerHTML = `
            <a href="${titleData.url}" style="display:block; color: black;width: 200rem;height: 230rem;">
                <img src="${img.src}" />
                <div>${titleData.name}</div>
            </a>
        `;
            titlesText.appendChild(title);
        }
    }
    let dao_new = await fetch('http://localhost:3001/categorys');
    let list_data = await dao_new.json();

    // 获取元素
    let titlesDiv = document.querySelector('.dao_new');
    let titleDatas = []

    // 遍历数据，创建元素并添加到页面
    for (let i = 0; i < list_data.length; i++) {
        if (list_data[i].level === 1) { // 只取level为1的数据
            let title = document.createElement('div');
            titleData = list_data[i];
            //已获取数据加入缓存
            titleDatas.push(titleData)
            //构建内容
            title.className = 'news'
            title.innerHTML = `
                <a href="${titleData.url}" style="display:block; color: black;width: 181rem;height: 80rem;">
                    <div class="title">${titleData.name}</div>
                </a>
            `
            title.addEventListener('click', function () {
                this.style.backgroundColor = 'white';
            });
            titlesDiv.appendChild(title);
        }
    }

})()